package eddy.yang.wordpad;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.Icon;

public class MyImageIcon implements Icon{
	
	private String imagename;
	private Image image;
	public MyImageIcon(String filename) {
		this.imagename = filename;
		
		File f = new File(imagename);
		
		if(f == null) return;
		
		try{
            image=ImageIO.read(f);
        }catch(Exception e) {
      }
	}
	
	public int getIconHeight() {
		return image.getHeight(null);
	}

	public int getIconWidth() {
		return image.getWidth(null);
	}

	public void paintIcon(Component c, Graphics g, int x, int y) {
		g.drawImage(image, x, y, null);
	}
}
